package com.xrj4j.k_tally.view.viewmodel

import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.ViewModel
import com.xrj4j.k_tally.db.AppDatabase
import com.xrj4j.k_tally.model.BillItem
import com.xrj4j.k_tally.model.BillItemDao
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow

class BillItemViewModel(private val dao: BillItemDao) : ViewModel() {

    private var itemList = MutableStateFlow(dao.loadBillList())

    fun deleteItem(item: BillItem) = dao.insert(item)
    fun insertItem(item: BillItem) = dao.insert(item)
    fun update(item: BillItem) = dao.update(item)
    fun userDaoChanged(): Boolean = dao.loadBillList() == itemList.value
    fun loadList(): Flow<List<BillItem>> = dao.loadBillList()
}